<?php

namespace App\Http\Service;

class UserInstance
{
    //创建静态私有的变量保存该类对象
    static private $instance;
    static private $user;

    //防止使用new直接创建对象
    private function __construct()
    {

    }

    private $setting = [];

    //防止使用clone克隆对象
    private function __clone()
    {
    }

    static public function getInstance()
    {
        //判断$instance是否是Singleton的对象，不是则创建
        if (!self::$instance instanceof self) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    //设置配置项
    public function set($user)
    {
        self::$user = ['id' => $user->id,
                       'name' => $user->name,
                       'created_at' => $user->created_at,
                       'mobile' => $user->mobile];
    }

    //读取配置项
    public function get()
    {
        return self::$user;
    }
}
